// pages/zhengCeList/zhengCeList.js
var app = getApp();
Page({
  data: {
    url: app.globalData.url,
    imgPath: app.globalData.url + "/file/showImage/",
    winHeight: "",//窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    list:[
    ]
  },
  // 滚动切换标签样式
  switchTab: function (e) {
    this.setData({
      currentTab: e.detail.current
    });
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function (e) {
    var cur = e.target.dataset.current;
    if (this.data.currentTaB == cur) { return false; }
    else {
      this.setData({
        currentTab: cur
      })
    }
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function () {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },
  onLoad: function () {
    var that = this;
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        that.setData({
          winHeight: calc
        });
      }
    });
    // 获取公告数据
    wx.request({
      url: app.globalData.url + '/index/policy/0',
      data: '',
      success: function(res) {
        console.log(res);
        var vlist = "list[0]"
        that.setData({
          [vlist]:res.data.result
        })
      },
    })
    wx.request({
      url: app.globalData.url + '/index/policy/1',
      data: '',
      success: function (res) {
        console.log(res);
        var vlist = "list[1]"
        that.setData({
          [vlist]: res.data.result
        })
      },
    })
    wx.request({
      url: app.globalData.url + '/index/policy/2',
      data: '',
      success: function (res) {
        var vlist = "list[2]"
        that.setData({
          [vlist]: res.data.result
        })
      },
    })
    wx.request({
      url: app.globalData.url + '/index/policy/3',
      data: '',
      success: function (res) {
        var vlist = "list[3]"
        that.setData({
          [vlist]: res.data.result
        })
      },
    })
    wx.request({
      url: app.globalData.url + '/index/policy/4',
      data: '',
      success: function (res) {
        var vlist = "list[4]"
        that.setData({
          [vlist]: res.data.result
        })
      },
    })
  },
  footerTap: app.footerTap
})